home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / Catalog.js < prev    next >
Encoding:
Text File  |  2007-04-11  |  8.1 KB  |  281 lines

  1. /****i* SOURCE_FILE/INFO
  2.     *
  3.     * NAME
  4.     *  Catalog.js
  5.     *
  6.     * USAGE
  7.     *  Part of Netobjects JavaScript Library.
  8.     *
  9.     * COPYRIGHT
  10.     *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.     *  All Rights Reserved.
  12.     *
  13.     *  This is an unpublished work protected by Website Pros, Inc.
  14.     *  as a trade secret, and is not to be used or disclosed except as
  15.     *  expressly provided in a written license agreement executed by
  16.     *  you and Website Pros, Inc.
  17.     *
  18.     *      <copyright@websitepros.com>
  19.     *
  20.     * NOTES
  21.     *  JavaScript code.
  22.     *
  23.     *****/
  24.  
  25. if (!IS.isModuleInitialized("IS.NOF.Catalog"))
  26. {
  27.     /****h* NOF_JavaScript_Library/NOF.Catalog
  28.     *
  29.     * NAME
  30.     *  NOF.Catalog
  31.     *
  32.     * DESCRIPTION
  33.     *
  34.     *
  35.     ****/
  36.     
  37.     /**
  38.     * Constructor    
  39.     * @param fsi_selection 
  40.     * @param profile
  41.     * @param name
  42.     */      
  43.     function NOF_Catalog(fsi_selection, profile, name){
  44.         this.__proto__  = NOF_Catalog;
  45.         
  46.         //private variables
  47.         this.app                   = NOF.App.getFSIApp(); 
  48.         this.app2                  = NOF.App.getFSIApp2();
  49.         
  50.         //public constants
  51.         this.INDEX_IS_TABLE       = 0x00000001;
  52.         this.INDEX_INCLUDE_TITLE  = 0x00000002;
  53.         this.DISPLAY_LAYOUT_MASK  = 0x0000000f;
  54.         this.TABLE_GENERATED_MASK = 0x00000800;
  55.         
  56.         //public variables
  57.         this.selection             = fsi_selection;
  58.         this.profile               = profile;
  59.         this.name                  = name;
  60.         this.currentIndex          = -1;
  61.         
  62.         this.list                  = new Array();
  63.         this.indexInSelection    = new Array();
  64.         
  65.         this.indexCatalog          = null; //ThumbnailPage;
  66.         this.displayCatalog        = null; //PhotoPage;
  67.         
  68.         this.internalTableCreated  =
  69.             ( this.selection != null && this.selection.GetTable() != null);//this value should be verified in subclass !
  70.         
  71.         if ( this.internalTableCreated && this.selection.GetTable().Name!=null ) {
  72.             this.name = this.selection.GetTable().Name; //read the real name of the catalog
  73.         }
  74.     }
  75.     
  76.     function NOF_Catalog_ProtoBuilder() {
  77.         
  78.         //interface
  79.         var method = NOF_Catalog.prototype;
  80.         
  81.         method.getIndexCatalog   = getIndexCatalog;
  82.         method.getDisplayCatalog = getDisplayCatalog;
  83.         
  84.         method.setCurrentIndex   = setCurrentIndex;
  85.         method.getCurrentIndex   = getCurrentIndex;
  86.         
  87.         method.get               = get;
  88.         method.add               = add;
  89.         method.removeAll         = removeAll;
  90.         method.remove            = remove;
  91.         method.size              = size;
  92.         
  93.         method.swapItems         = swapItems;
  94.         
  95.         method.alterTable        = alterTable;
  96.         method.createTable       = createTable;
  97.         method.setTable          = setTable;
  98.         
  99.         method.isInternalTableCreated = isInternalTableCreated;
  100.         
  101.         
  102.         
  103.         //interface implementation
  104.         
  105.         
  106.         /**
  107.         * get a record from the list
  108.         * @param i index of the the item
  109.         * @return the i-th item in the list or currentIndex element, if i is null
  110.         */
  111.         
  112.         function get (i){
  113.             var index = this.currentIndex;
  114.             if(i!=null){
  115.                 index = i;
  116.             }
  117.             return this.list[index];
  118.         }
  119.         
  120.         
  121.         function add(q, values, position) {
  122.             var index = position != null ? position : this.list.length;
  123.             this.list[index] = q;     //add q element at the end of the list, modify here to insert it at a specified position
  124.             this.indexInSelection[index] = index;
  125.             
  126.             // Update existing item
  127.             if (position != null && position >= 0)
  128.                 this.selection.SetIndex(position);
  129.             // Insert new Item
  130.             else 
  131.             this.selection.NewRecord();
  132.                 
  133.                 
  134.             for ( var i = 0; i < values.length; i++ ) {
  135.                 this.selection.SetField(values[i][0], values[i][1]);//write corresponding data into table fields
  136.             }
  137.             this.selection.Update();
  138.             this.setCurrentIndex(index); //set current index the last element inserted
  139.         }
  140.         
  141.         
  142.         function getIndexCatalog(){
  143.             return this.indexCatalog;
  144.         }
  145.         
  146.         function getDisplayCatalog(){
  147.             return this.displayCatalog;
  148.         }
  149.         
  150.         function getCurrentIndex(){
  151.             return this.currentIndex;
  152.             
  153.         }
  154.         
  155.         function removeAll() {
  156.             for ( var i = this.size() - 1; i >= 0; i-- ) {
  157.                 if( this.remove( i ) == false ){
  158.                     //OO! ??
  159.                 }
  160.             }
  161.             this.list                  = new Array();
  162.             this.indexInSelection    = new Array();
  163.             
  164.         }
  165.         
  166.         function remove( index ){
  167.             
  168.             var i = (index != null ) ? index : this.currentIndex;
  169.             
  170.             
  171.             var q = this.indexInSelection[i];
  172.             //NOF.util_logging_ConsoleLogger_global.info( "Catalog.remove item "+i+" - in selection "+q);
  173.             
  174.             this.selection.SetIndex( q );
  175.             
  176.             var image          = this.selection.GetField('Image');
  177.             var displayflags   = this.selection.GetField('ImageFlags') - 0;
  178.             var displaywidth   = this.selection.GetField('ImageWidth') - 0;
  179.             var displayheight  = this.selection.GetField('ImageHeight') - 0;
  180.             var rotation       = this.selection.GetField('ImageRotation') - 0;
  181.             var displayquality = this.selection.GetField('ImageQuality') - 0;
  182.             var displayformat  = this.selection.GetField('ImageFormat');
  183.             var indexflags     = this.selection.GetField('ImageTnFlags') - 0;
  184.             var indexwidth     = this.selection.GetField('ImageTnWidth') - 0;
  185.             var indexheight    = this.selection.GetField('ImageTnHeight') - 0;
  186.             var indexquality   = this.selection.GetField('ImageTnQuality') - 0;
  187.             var indexformat    = this.selection.GetField('ImageTnFormat');
  188.             
  189.             //NOF.util_logging_ConsoleLogger_global.info( "Catalog.remove item from selection "+q+"\n imagePath="+image);
  190.             
  191.             if ((displayflags & this.TABLE_GENERATED_MASK) != 0)
  192.                 this.selection.FreeKey(image, displaywidth, displayheight, rotation, displayquality, displayformat);
  193.             
  194.             if ((indexflags & this.TABLE_GENERATED_MASK) != 0)
  195.                 this.selection.FreeKey(image, indexwidth, indexheight, rotation, indexquality, indexformat);
  196.             
  197.             this.selection.DeleteRecord();
  198.             this.selection.Update();
  199.             
  200.             this.list.removeItem(i);
  201.             
  202.             this.indexInSelection.removeItem(i);
  203.             // decrease all indexes in the selection greater than q
  204.             for( var j = 0; j < this.indexInSelection.length; j++ ) {
  205.                 if( q <= this.indexInSelection[j] ) {
  206.                     this.indexInSelection[j] -= 1;
  207.                 }
  208.             }
  209.             
  210.             if( i > 0 ) {
  211.                 this.setCurrentIndex( i-1 );
  212.             } else {
  213.                 this.setCurrentIndex( 0 );
  214.             }
  215.             
  216.             //NOF.util_logging_ConsoleLogger_global.info( "Catalog.remove "+      " this.indexInSelection = "+this.indexInSelection.join()+ "\n\n currentIndex=="+this.currentIndex);
  217.             
  218.             return true;
  219.         }
  220.         
  221.         function swapItems(i1, i2){
  222.             
  223.             //NOF.util_logging_ConsoleLogger_global.info( "Catalog.swapItems "+i1+" - "+i2+", \n"+ this.list[i1].imagePath+"\n"+this.list[i2].imagePath+"\n"+ " indexInSelection = "+this.indexInSelection[i1]+" - "+this.indexInSelection[i2]);
  224.             
  225.             var tmp = this.list[i1];
  226.             this.list[i1] = this.list[i2];
  227.             this.list[i2] = tmp;
  228.             
  229.             var tmpI = this.indexInSelection[i1];
  230.             this.indexInSelection[i1] = this.indexInSelection[i2];
  231.             this.indexInSelection[i2] = tmpI;
  232.             
  233.             //NOF.util_logging_ConsoleLogger_global.info( "Catalog.swapItems "+i1+" - "+i2+", \n"+ this.list[i1].imagePath+"\n"+this.list[i2].imagePath+"\n"+ " indexInSelection = "+this.indexInSelection[i1]+" - "+this.indexInSelection[i2]+"\n\n"+ " this.indexInSelection = "+this.indexInSelection.join());
  234.         }
  235.         
  236.         function size(){
  237.             return this.selection.Count();
  238.             //should be the same as this._list
  239.         }
  240.         
  241.         
  242.         function setCurrentIndex(index){
  243.             //this.selection.SetIndex(index);
  244.             this.currentIndex = index;
  245.         }
  246.         
  247.         function setTable (table){
  248.             return this.selection.SetTable(table);
  249.         }
  250.         
  251.         function createTable (name,values){
  252.             var theTable = this.app.NewTable(name);
  253.             if (theTable){
  254.                 for(var i=0;i<values.length;i++)
  255.                     theTable.AddField(values[i][0],values[i][1]);
  256.                 
  257.                 this.internalTableCreated = this.selection.SetTable(theTable);
  258.             }
  259.             return this.internalTableCreated;
  260.         }
  261.         
  262.         function alterTable(values){
  263.             var theTable = this.selection.GetTable();
  264.             if (theTable){
  265.                 for(var i=0;i<values.length;i++){
  266.                     if (! theTable.FieldExists(values[i][0])) {
  267.                         theTable.AddField(values[i][0],values[i][1]);
  268.                     }
  269.                 }
  270.             }
  271.         }
  272.         
  273.         function isInternalTableCreated() {
  274.             return this.internalTableCreated;
  275.         }
  276.     }
  277.     
  278.     NOF_Catalog_ProtoBuilder();
  279.     NOF.__proto__.Catalog = NOF_Catalog;
  280. }
  281.